import React, { Component } from 'react'
import './Footer.css'
import PropTypes from 'prop-types'

export default class Footer extends Component {
  static propTypes = {
    todos: PropTypes.array.isRequired,
    clearAll: PropTypes.func.isRequired,
    chooseAll: PropTypes.func.isRequired,
  }

  render() {
    let { todos } = this.props
    let total = todos.reduce((pre, v) => pre + (v.done ? 1 : 0), 0)
    return (
      <div className="todo-footer">
        <label>
          <input type="checkbox" onClick={this.chooseAllInFooter} />
        </label>
        <span>
          <span>已完成{total}</span> / 全部{todos.length}
        </span>
        <button onClick={this.handleClearAllDone} className="btn btn-danger">
          清除已完成任务
        </button>
      </div>
    )
  }
  //清楚所有完成的项目
  handleClearAllDone = () => {
    this.props.clearAll()
  }

  chooseAllInFooter = (e) => {
    this.props.chooseAll(e.target.checked)
  }
}
